﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class ModifierImportesForm : Form
    {
        private Importés Imp = new Importés();

        public Importés IMP
        {
            get { return Imp; }
            set { Imp = value; }
        }
        public RechercherImpotésForm RechercheImpform { get; set; }
        public ModifierImportesForm()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboBoxExp.DataSource = context.Expéditeur;
            comboBoxExp.DisplayMember = "Nom_Expéditeur";
            comboBoxExp.ValueMember = "id_expéditeur";
            comboBoxExp.SelectedItem = null;
        }

        private void ModifierImportesForm_Load(object sender, EventArgs e)
        {

        }

        public void InitialiserChamps()
        {
            txtnombre.Text = Imp.Num_message.ToString();
            txtnum.Text = Imp.Num_enregistre.ToString();
            txtobjet.Text = Imp.Objet;
            dateTimePickerdateenv.Value = Imp.Date_envoi.Value;
            dateTimePickerrec.Value = Imp.Date_réception.Value;
            comboBoxExp.SelectedValue = Imp.Expéditeur.id_expéditeur;
        }

        private void btnajouter_Click(object sender, EventArgs e)
        {

            RAMEDEntities1 Context = SingletonContext.GetContext();
            Importés Imp = new Importés();
            Imp = Context.Importés.Where(d => d.Id_message_importé == IMP.Id_message_importé).First();
            Imp.Num_message = utitlitaire.CasterString(txtnombre.Text);
            Imp.Num_enregistre = utitlitaire.CasterString(txtnum.Text);
            Imp.Objet = txtobjet.Text;
            Imp.Date_envoi = dateTimePickerdateenv.Value;
            Imp.Date_réception = dateTimePickerrec.Value;

            Imp.id_expéditeur = ((Expéditeur)comboBoxExp.SelectedItem).id_expéditeur;
            RechercheImpform.mettreAjourFormGridView();
            Context.SaveChanges();
            this.Dispose();
           
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void modifierImages_Click(object sender, EventArgs e)
        {
            ImageviewerImprte imageviexerimp = new ImageviewerImprte();
            foreach (Image_Message_Importé imageimp in Imp.Image_Message_Importé)
                imageviexerimp.images.Add(utitlitaire.ConvertirBinaryAImage(imageimp.Image_));
            imageviexerimp.Show();
        }
       
    }
}
